package com.smartcampusbackend.controller;

import com.smartcampusbackend.model.OperationLog;
import com.smartcampusbackend.service.OperationLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/operation-logs")
public class OperationLogController {
    @Autowired
    private OperationLogService operationLogService;

    @GetMapping
    public List<OperationLog> queryLogs(
            @RequestParam(required = false) String businessType,
            @RequestParam(required = false) String operatorRole,
            @RequestParam(required = false) String operationType,
            @RequestParam(required = false) String businessId,
            @RequestParam(required = false) String status,
            @RequestParam(required = false) String startTime,
            @RequestParam(required = false) String endTime,
            @RequestParam(required = false) String userRole
    ) {
        List<OperationLog> logs = operationLogService.queryLogs(businessType, operatorRole, operationType, businessId, status, startTime, endTime);
        if (userRole != null) {
            if (userRole.equals("学生")) {
                logs.removeIf(log -> "职称申请".equals(log.getBusinessType()));
            } else if (userRole.equals("教师")) {
                logs.removeIf(log -> "选课".equals(log.getBusinessType()) || "退课".equals(log.getBusinessType()) || "毕业申请".equals(log.getBusinessType()) || "毕业审批".equals(log.getBusinessType()));
            } else if (userRole.equals("管理员")) {
                logs.removeIf(log -> "选课".equals(log.getBusinessType()) || "退课".equals(log.getBusinessType()));
            }
        }
        return logs;
    }
} 